//
//  ConversionLayer.cpp
//  ATM Killer
//
//  Created by iMac on 10/15/14.
//
//

#include "ConversionLayer.h"
ConversionLayer::ConversionLayer() {
    this->mainLayer = 0;
    this->createLayers();
    this->createLayersContent();
}

ConversionLayer::~ConversionLayer() {
    
}

void ConversionLayer::onEnter() {
    Layer::onEnter();
}

void ConversionLayer::onExit() {
    Layer::onExit();
    this->removeAllChildrenWithCleanup(true);
}

void ConversionLayer::createLayers(){
    this->grayLayer = UGLayerColor::create();
    this->grayLayer->initWithColor(Color4B(0,0,0,100));
    this->addChild(this->grayLayer);
    
    this->mainLayer = UGLayer::create();
    this->addChild(this->mainLayer);
}

void ConversionLayer::createLayersContent(){
    GameModel* gameModel = GameModel::getInstance();
    Size gameSize = gameModel->getDisplayResolutionSize();
    //conversionBoard
    this->conversionBoard = new Face();
    this->conversionBoard->initWithSpriteFrameName(ANI_CONVERSION_BOARD);
    this->conversionBoard->setPosition(gameSize.width/2, gameSize.height/2);
    this->mainLayer->addChild(this->conversionBoard);
    
    //close button
    UGMenu* closeMenu = UGMenu::create();
    closeMenu->setPosition(Point::ZERO);
    this->conversionBoard->addChild(closeMenu);
    
    MenuItemSprite* closeButton = Utils::createButton((char*)ANI_BUTTON_CLOSE_1, (char*)ANI_BUTTON_CLOSE_2);
    closeButton->setPosition(this->conversionBoard->getContentSize().width + closeButton->getContentSize().width/2 - 20, this->conversionBoard->getContentSize().height - closeButton->getContentSize().height/2);
    closeMenu->addChild(closeButton);
    closeButton->setCallback(CC_CALLBACK_1(ConversionLayer::onCloseAchievementBoard, this));
    
    //conversion label
    char conversionText[1000];
    string text;
    text = "Legend of Large Numbers\n1K	=	1,000	=	One Thousand\n1M	=	1,000K	=	One Million\n1B	=	1,000M	=	One Billion\n1T	=	1,000B	=	One Trillion\n1q	=	1,000T	=	One Quadrillion\n1Q	=	1,000q	=	One Quintillion\n1s	=	1,000Q	=	One Sextillion\n1S	=	1,000s	=	One Septillion\n1O	=	1,000S	=	One Octillion\n1N	=	1,000O	=	One Nonillion\n1d	=	1,000N	=	One Decillion\n1U	=	1,000d	=	One Undecillion\n1D	=	1,000U	=	One Duodecillion\n";
    sprintf(conversionText, "%s", text.c_str());
    Label* conversionLabel = Utils::createLabel(conversionText, (char*)FONT_MYRIADPRO_BOLD, 22);
    conversionLabel->setPosition(this->conversionBoard->getContentSize().width/2, this->conversionBoard->getContentSize().height/2 + 10);
    this->conversionBoard->addChild(conversionLabel);
}

void ConversionLayer::update(float dt) {
    GameModel* gameModel = GameModel::getInstance();
    if(gameModel->getGameState() == GS_CONVERSION){
        this->grayLayer->setVisible(true);
        this->mainLayer->setVisible(true);
    } else {
        this->grayLayer->setVisible(false);
        this->mainLayer->setVisible(false);
    }
}

void ConversionLayer::onCloseAchievementBoard(Ref* sender) {
        this->notify(REQ_PAUSE, EVT_CLICK_BUTTON, NULL, 0, NULL);
}